<template>
  <el-tabs v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="个人信息" name="first">
      <el-form ref="userInfo" :rules="userInforules" :model="userInfo" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="userInfo.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-select v-model="userInfo.gender" placeholder="请选择性别">
                <el-option label="男" value="0"></el-option>
                <el-option label="女" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="生日" prop="birthday">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="userInfo.birthday"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                style="width: 100%;"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证" prop="idNum">
              <el-input v-model="userInfo.idNum"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="手机" prop="mobile">
              <el-input v-model="userInfo.mobile"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="住址" prop="homeAddress">
              <el-input v-model="userInfo.homeAddress"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="电子邮件" prop="email">
              <el-input v-model="userInfo.email"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-select v-model="userInfo.nation" placeholder="">
                <el-option v-for="nation in nations"
                  :key="nation.value"
                  :label="nation.label"
                  :value="nation.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="文化程度" prop="education">
              <el-input v-model="userInfo.education"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位名称">
              <el-input v-model="orginfo.orgName" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="单位编号" prop="quaId" v-show="false">
              <el-input v-model.number="userInfo.quaId"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="裁判等级" prop="certificateNum">
              <el-select v-model="userInfo.level" :disabled="true">
                <el-option v-for="level in relevel"
                  :key="level.id"
                  :label="level.dictName"
                  :value="level.id">
                </el-option>
              </el-select>
            </el-form-item> 
          </el-col>
          <el-col :span="12">
            <el-form-item label="裁判证号" prop="certificateNum">
              <el-input v-model="userInfo.certificateNum" :disabled="true"></el-input>
            </el-form-item>

          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="saveUserInfo">保存用户信息</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-tab-pane>

    <el-tab-pane label="单位信息" name="second">
      <el-form  label-width="100px" :model="orginfo" class="nbform">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="单位名称">
              <el-input v-model="orginfo.orgName" class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地址">
              <el-input v-model="orginfo.address" class="nb"  readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="电话">
              <el-input v-model="orginfo.tel"  class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人">
              <el-input v-model="orginfo.principalName"  class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="负责人电话">
              <el-input v-model="orginfo.principalMobile"  class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人">
              <el-input v-model="orginfo.contactName"  class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联系人电话">
              <el-input v-model="orginfo.contactMobile"  class="nb" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label>
              <el-button type="primary" @click="showChangeOrg">设置单位</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        

        <!-- 更换单位 -->
        <el-dialog
          title="设置单位"
          :visible.sync="changeOrgVisible"
          :close-on-click-modal="false"
          width="70%"
        >
          <el-form :model="filterOrg" ref="orgfilterform" label-width="100px">
            <el-row :gutter="20">
              <el-col :span="10">
                <el-form-item label="单位名称">
                    <el-input v-model="filterOrg.keyword"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                  <el-form-item label-width="0">
                    <el-button type="primary" @click="firstQueryOrg">搜索</el-button>
                  </el-form-item>
              </el-col>
              <el-col :span="10">
            <el-form-item label="已选择">
              <el-input v-model="filterOrg.orgName" readonly></el-input>
            </el-form-item>
              </el-col>
          </el-row>
          </el-form>


          

          <el-table :data="tempOrgList">
            <el-table-column prop="orgName" label="单位名称" width></el-table-column>
            <el-table-column prop="address" label="单位地址" width></el-table-column>
            <el-table-column prop="principalName" label="负责人" width></el-table-column>
            <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button size="small" @click="handleSetOrg(scope.$index, scope.row)">选择</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!--工具条-->
          <el-col :span="24" class="toolbar">
            <el-pagination
              layout="prev, pager, next"
              @current-change="handleCurrentChange"
              :page-size="5"
              :total="orgtotal"
              style="float:right;"
            ></el-pagination>
          </el-col>

          <span slot="footer">
            <el-button @click="changeOrgVisible= false">取 消</el-button>
            <el-button type="primary" @click="changeOrg">确 定</el-button>
          </span>
        </el-dialog>
      </el-form>
    </el-tab-pane>

    <el-tab-pane label="资格认证" name="third">
      <el-row>
        <el-col :span="24" align="right">
          <el-button type="primary" size="small" @click="showQualification('new')">增加资格认证</el-button>
        </el-col>
      </el-row>

      <el-table :data="qualificationList" style="width: 100%">
        <el-table-column prop="approveDate" label="批准日期" width="180"></el-table-column>
        <el-table-column prop="approveOrg" label="批准机构" width="180"></el-table-column>
        <el-table-column prop="level" label="级别" :formatter="formatReLevel"></el-table-column>
        <el-table-column prop="grade" label="成绩"></el-table-column>
        <el-table-column prop="certificateNum" label="证书编号"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="small" @click="handleEditqualification(scope.$index, scope.row)">编辑</el-button>
            <el-button
              type="danger"
              size="small"
              @click="handleDelqualification(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog title="增加资格认证" :visible.sync="qualificationVisible" :close-on-click-modal="false">
        <el-form
          ref="qualificationForm"
          :rules="qualificationrules"
          :model="qualificationForm"
          label-width="90px"
        >
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="批准日期" prop="approveDate">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="qualificationForm.approveDate"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  style="width: 100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="批准机构" prop="approveOrg">
                <el-input v-model="qualificationForm.approveOrg" placeholder="请录入批准机构"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="成绩" prop="grade">
                <el-input v-model="qualificationForm.grade" placeholder="请录入成绩"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="级别" prop="level">
                <el-select v-model="qualificationForm.level" placeholder="请选择证书级别">
                  <el-option
                    v-for="level in relevel"
                    :label="level.dictName"
                    :value="level.id"
                    :key="level.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="证书编号" prop="certificateNum">
                <el-input v-model="qualificationForm.certificateNum" placeholder="请输入证书编号"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12"></el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="qualificationVisible = false">取 消</el-button>
          <el-button type="primary" @click="addQualification">保存资格认证</el-button>
        </div>
      </el-dialog>
    </el-tab-pane>

    <el-tab-pane label="培训经历" name="fourth">
      <el-row>
        <el-col :span="24" align="right">
          <el-button type="primary" size="small" @click="showTrain('new')">增加培训经历</el-button>
        </el-col>
      </el-row>
      <el-table :data="reTrainList" style="width: 100%">
        <el-table-column prop="startDate" label="起始日期" width="100"></el-table-column>
        <el-table-column prop="endDate" label="结束日期" width="100"></el-table-column>
        <el-table-column prop="trainName" label="培训名称"></el-table-column>
        <el-table-column prop="sponsor" label="主办单位"></el-table-column>
        <el-table-column prop="undertaker" label="承办单位"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="small" @click="showreTrainListEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
              type="danger"
              size="small"
              @click="reTrainListDel(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog title="培训经历" :visible.sync="reTrainFormVisable" :close-on-click-modal="false">
        <el-form
          ref="reTrainForm"
          :rules="reTrainFormRules"
          :model="reTrainForm"
          label-width="90px"
        >
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="起始日期" prop="startDate">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="reTrainForm.startDate"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  style="width: 100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束日期" prop="endDate">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="reTrainForm.endDate"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  style="width: 100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="培训名称" prop="trainName">
                <el-input v-model="reTrainForm.trainName" placeholder="请录入培训名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主办单位" prop="sponsor">
                <el-input v-model="reTrainForm.sponsor" placeholder="请录入培训名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="承办单位" prop="undertaker">
                <el-input v-model="reTrainForm.undertaker" placeholder="请录入承办单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12"></el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="reTrainFormVisable = false">取 消</el-button>
          <el-button type="primary" @click="addTrain">保存培训经历</el-button>
        </div>
      </el-dialog>
    </el-tab-pane>

    <el-tab-pane label="执裁经历" name="five">
      <el-row>
        <el-col :span="24" align="right">
          <el-button type="primary" size="small" @click="showJudg('new')">增加执裁经历</el-button>
        </el-col>
      </el-row>
      <el-table :data="reJudgeList" style="width: 100%">
        <el-table-column
          prop="competitionLevel"
          label="赛事级别"
          width="100"
          :formatter="formatcomlevel"
        ></el-table-column>
        <el-table-column prop="startDate" label="起始日期" width="100"></el-table-column>
        <el-table-column prop="endDate" label="结束日期" width="100"></el-table-column>
        <el-table-column prop="competitionName" label="比赛名称" width="180"></el-table-column>
        <el-table-column prop="sponsor" label="主办单位"></el-table-column>
        <el-table-column prop="undertaker" label="承办单位"></el-table-column>
        <el-table-column prop="sponsor" label="主办单位"></el-table-column>
        <el-table-column prop="duty" label="制裁职务" width="100" :formatter="formatpositionlevel"></el-table-column>
        <el-table-column prop="evaluate" label="制裁评价"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="small" @click="showreJudgeListEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
              type="danger"
              size="small"
              @click="reJudgeListDel(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog title="增加执裁经历" :visible.sync="reJudgeFormVisable" :close-on-click-modal="false">
        <el-form
          ref="reJudgeForm"
          :rules="reJudgeFormRules"
          :model="reJudgeForm"
          label-width="90px"
        >
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="起始日期" prop="startDate">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="reJudgeForm.startDate"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  style="width: 100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="结束日期" prop="endDate">
                <el-date-picker
                  type="date"
                  placeholder="选择日期"
                  v-model="reJudgeForm.endDate"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  style="width: 100%;"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="比赛名称" prop="competitionName">
                <el-input v-model="reJudgeForm.competitionName" placeholder="请录入比赛名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主办单位" prop="sponsor">
                <el-input v-model="reJudgeForm.sponsor" placeholder="请录入主办名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="承办单位" prop="undertaker">
                <el-input v-model="reJudgeForm.undertaker" placeholder="请录入承办单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="级别" prop="competitionLevel">
                <el-select v-model="reJudgeForm.competitionLevel" placeholder="请录入赛事级别">
                  <el-option
                    v-for="level in recomlevel"
                    :key="level.id"
                    :label="level.dictName"
                    :value="level.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="职务" prop="duty">
                <el-select v-model="reJudgeForm.duty" placeholder="请录入执裁职务">
                  <el-option
                    v-for="position in repositionlevel"
                    :key="position.id"
                    :label="position.dictName"
                    :value="position.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="评价" prop="evaluate">
                <el-input v-model="reJudgeForm.evaluate" placeholder="请录入评价"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="reJudgeFormVisable = false">取 消</el-button>
          <el-button type="primary" @click="addJudge">保存执裁经历</el-button>
        </div>
      </el-dialog>

      <!-- 资格认证添加表单 -->
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import util from "../../common/js/util";
import mycommon from '../../common/enum'
import { getReLeve, getComLeve, getPositionLeve } from "../../api/api";
import { valid } from "semver";
export default {
  data() {
    return {
      activeName: "first",
      editSatus: {
        qualification: false,
        train: false,
        judge: false
      },
      nations:[],
      relevel: [],
      releveldict: {},
      recomlevel: [],
      recomleveldict: {},
      repositionlevel: [],
      repositionleveldict: {},
      msg: "",
      userId: 0,
      form: {
        name: ""
      },
      userInfo: {
        id: "",
        name: "",
        gender: 0,
        birthday: "",
        idNum: "",
        mobile: "",
        homeAddress: "",
        email: "",
        certificateNum: "",
        education: "",
        nation: "",
        quaId: 0
      },
      userInforules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" }
        ],
        gender: [{ required: true, message: "请选择性别", trigger: "change" }],
        birthday: [
          {
            type: "string",
            required: true,
            message: "请选择出生日期",
            trigger: "change"
          }
        ],
        idNum: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
          { min: 18, max: 18, message: "请输入18位身份证号", trigger: "blur" }
        ],
        mobile: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { min: 11, max: 11, message: "请输入11位手机号", trigger: "blur" }
        ],
        homeAddress: [
          { required: true, message: "请输入家庭住址", trigger: "blur" }
        ],
        email: [
          {
            type: "email",
            required: true,
            message: "请输入电子邮箱地址",
            trigger: "blur"
          }
        ],
        quaId: [{ required: true, message: "输入单位id", trigger: "blur" }]
      },
      orginfo: {
        id: "",
        orgName: "",
        address: "",
        tel: "",
        principalName: "",
        principalMobile: "",
        contactName: "",
        contactMobile: ""
      },
      changeOrgVisible: false,
      filterOrg: {
        page: 0,
        keyword: "",
        orgName: "",
        quaId: ""
      },
      tempOrgList: [],
      orgtotal: 0,
      // 资格认证 例子数据 啥后删除
      qualificationList: [],
      qualificationVisible: false,
      qualificationForm: {
        reId: 0,
        approveDate: "",
        approveOrg: "",
        certificateNum: "",
        grade: "",
        level: ""
      },
      qualificationrules: {
        approveOrg: [
          { required: true, message: "请输入批准机构", trigger: "blur" },
          { min: 2, max: 20, message: "长度在 2 到 20 个字符", trigger: "blur" }
        ],
        approveDate: [
          {
            type: "string",
            required: true,
            message: "请选择批准日期",
            trigger: "change"
          }
        ],
        certificateNum: [
          { required: true, message: "请输入证书编号", trigger: "blur" }
        ],
        grade: [{ required: true, message: "请输入成绩", trigger: "blur" }],
        level: [{ required: true, message: "请选择级别", trigger: "change" }]
      },
      reTrainList: [],
      reTrainFormVisable: false,
      reTrainForm: {
        reId: 0,
        id: 0,
        startDate: "",
        endDate: "",
        trainName: "",
        sponsor: "",
        undertaker: ""
      },
      reTrainFormRules: {
        startDate: [
          {
            type: "string",
            required: true,
            message: "请选择开始日期",
            trigger: "change"
          }
        ],
        endDate: [
          {
            type: "string",
            required: true,
            message: "请选择结束日期",
            trigger: "change"
          }
        ],
        trainName: [
          { required: true, message: "请输入培训名称", trigger: "blur" },
          { min: 2, max: 20, message: "长度在 2 到 20 个字符", trigger: "blur" }
        ],
        sponsor: [
          { required: true, message: "请输入主办单位", trigger: "blur" },
          { min: 2, max: 20, message: "长度在 2 到 20 个字符", trigger: "blur" }
        ],
        undertaker: [
          { required: true, message: "请输入承办单位", trigger: "blur" },
          { min: 2, max: 20, message: "长度在 2 到 20 个字符", trigger: "blur" }
        ]
      },
      reJudgeForm: {
        reId: 0,
        startDate: "",
        endDate: "",
        competitionName: "",
        competitionLevel: 0,
        sponsor: "",
        undertaker: "",
        duty: "",
        evaluate: ""
      },
      reJudgeFormRules: {
        startDate: [
          {
            type: "string",
            required: true,
            message: "请选择开始日期",
            trigger: "change"
          }
        ],
        endDate: [
          {
            type: "string",
            required: true,
            message: "请选择结束日期",
            trigger: "change"
          }
        ],
        competitionName: [
          { required: true, message: "请输入比赛名称", trigger: "blur" }
        ],
        competitionLevel: [
          { required: true, message: "请输入比赛级别", trigger: "blur" }
        ],
        sponsor: [
          { required: true, message: "请输入主办单位", trigger: "blur" }
        ],
        undertaker: [
          { required: true, message: "请输入承办单位", trigger: "blur" }
        ],
        duty: [{ required: true, message: "请输入执裁职务", trigger: "blur" }],
        evaluate: [{ required: true, message: "请输入评价", trigger: "blur" }]
      },
      reJudgeFormVisable: false,
      reJudgeList: [],
      isloaded: {
        first: false,
        seconde: false,
        four: false,
        five: false
      }
    };
  },
  methods: {
    //  裁判员级别格式化,
    formatReLevel(row) {
      return this.releveldict["lv" + row.level];
    },
    // 性别显示转换
    formatSex(row) {
      return row.gender == 0 ? "男" : row.gender == 1 ? "女" : "保密";
    },
    // 赛事级别过滤器
    formatcomlevel(row) {
      return this.recomleveldict["lv" + row.competitionLevel];
    },
    // 裁判员职业过滤器
    formatpositionlevel(row) {
      return this.repositionleveldict["lv" + row.duty];
    },

    handleCurrentChange(val) {
      this.filterOrg.page = val;
      this.queryOrg();
    },
    handleClick(tab, event) {
      let tabname = tab.name;
      if (!this.isloaded[tabname]) {
        if (tabname === "third") {
          this.getQualification();
        }
        if (tabname === "fourth") {
          this.getTrainList();
        }
        if (tabname === "five") {
          this.getJudgeList();
        }
        // 点击tab后 如果该tab获取过数据 就暂时不要再次获取，除非增加后 强制更新
        this.isloaded[tabname] = true;
      } else {
        return false;
      }
    },
    // 获取该用户的单位信息(机构信息)
    getOrgInfo() {
      if (this.userInfo.quaId) {
        this.axios
          .get(`/referee/manage/org?id=${this.userInfo.quaId}`)
          .then(result => {
            this.orginfo = result.data.data.list[0];
          })
          .catch(err => {});
      }
    },
    showChangeOrg() {
      this.changeOrgVisible = true;
      this.filterOrg.keyword = "";
      this.filterOrg.quaId = this.orginfo.id;
      this.filterOrg.orgName = this.orginfo.orgName;

      this.queryOrg();

      // this.tempOrgList = [];
    },
    firstQueryOrg() {
      this.filterOrg.page = 1; // 每次点击搜素，将页码重置为1
      this.queryOrg();
    },
    queryOrg() {
      this.axios
        .get(
          `/referee/manage/org?orgName=${this.filterOrg.keyword}&pageNum=${
            this.filterOrg.page
          }&pageSize=5`
        )
        .then(result => {
          if (
            result.data.code === "0000" &&
            result.data.data.list.length >= 1
          ) {
            this.tempOrgList = result.data.data.list;
            this.orgtotal = result.data.data.total;
          } else {
            this.$message("没有符合的机构");
          }
        })
        .catch(err => {});
    },
    handleSetOrg(index, row) {
      this.filterOrg.orgName = row.orgName;
      this.filterOrg.quaId = row.id;
    },
    // 更新单位单位信息id
    changeOrg() {
      if (this.filterOrg.quaId) {
        if (this.userInfo.quaId !== this.filterOrg.quaId) {
          this.userInfo.quaId = this.filterOrg.quaId;
          this.axios
            .post(`/referee/manage/re`, JSON.stringify(this.userInfo))
            .then(result => {
              if (result.data.code === "0000") {
                this.changeOrgVisible = false;
                // 更新组织信息
                this.getOrgInfo();
                this.$message("单位信息修改成功");
              }
            })
            .catch(err => {});
        } else {
          this.$message("跟原来单位相同,请选择新单位或取消");
        }
      } else {
        this.$message("请选择注册单位");
      }
    },
    // 添加培训经历弹出框
    showTrain(type) {
      if (type === "new") {
        this.reTrainForm = {
          startDate: "",
          endDate: "",
          trainName: "",
          sponsor: "",
          undertaker: ""
        };
        this.editSatus.train = false;
      } else {
        this.editSatus.train = true;
      }

      this.reTrainFormVisable = true;
      this.$nextTick(() => {
        this.$refs.reTrainForm.clearValidate();
      });
    },
    // 验证数据 发送添加培训的请求
    addTrain() {
      this.$refs.reTrainForm.validate(valid => {
        if (valid) {
          if (this.editSatus.train) {
            // 编辑培训记录
            this.reTrainForm.reId = this.userId;
            this.axios
              .put("/referee/manage/re/train", JSON.stringify(this.reTrainForm))
              .then(result => {
                if (result.data.code === "0000") {
                  this.reTrainFormVisable = false;
                  this.$message("修改成功");
                  this.getTrainList();
                }
              })
              .catch(err => {});
          } else {
            // 新增培训记录
            this.reTrainForm.reId = this.userId;
            this.axios
              .post(
                "/referee/manage/re/train",
                JSON.stringify(this.reTrainForm)
              )
              .then(result => {
                if (result.data.code === "0000") {
                  this.reTrainFormVisable = false;
                  this.$message("添加成功");
                  this.getTrainList();
                }
              })
              .catch(err => {});
          }
        } else {
          return false;
        }
      });
    },
    // 删除培训记录
    reTrainListDel(index, row) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const trainId = row.id;
          this.axios
            .delete(`/referee/manage/re/train/${trainId}`)
            .then(result => {
              if (result.data.code === "0000") {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
              }
              this.getTrainList();
            })
            .catch(err => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 显示编辑培训经历窗口，初始化数据
    showreTrainListEdit(idex, row) {
      this.reTrainForm = row;
      this.showTrain("edit");
    },

    // 添加资格认证
    showQualification(type) {
      // 清除表单验证
      this.qualificationVisible = true;
      // 如果是新建，清空表单数据
      if (type === "new") {
        this.editSatus.qualification = false;
        this.qualificationForm = {
          approveDate: "",
          approveOrg: "",
          certificateNum: "",
          grade: "",
          level: ""
        };
      }
      this.$nextTick(() => {
        this.$refs.qualificationForm.clearValidate();
      });
    },
    // 添加资格认证
    addQualification() {
      this.$refs.qualificationForm.validate(valid => {
        if (valid) {
          this.qualificationForm.reId = this.userId;

          if (this.editSatus.qualification) {
            // 更新方式
            this.axios
              .put(
                "/referee/manage/re/qualification",
                JSON.stringify(this.qualificationForm)
              )
              .then(result => {
                this.qualificationVisible = false;
                this.$message("添加成功");
                this.getQualification();
                this.getUserInfo();


                // 重新获取执裁列表
              })
              .catch(err => {});
            this.editSatus.qualification = false;
          } else {
            // 新建方式
            this.axios
              .post(
                "/referee/manage/re/qualification",
                JSON.stringify(this.qualificationForm)
              )
              .then(result => {
                this.qualificationVisible = false;
                this.$message("添加成功");
                this.getQualification();
                this.getUserInfo();
                // 重新获取执裁列表
              })
              .catch(err => {});
          }
        } else {
          return false;
        }
      });
    },
    // 保存修改后的用户信息
    saveUserInfo() {
      this.$refs.userInfo.validate(valid => {
        if (valid) {
          this.userInfo.id = this.userId;
          this.$confirm("保存用户信息", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              // 表单数据验证通过,并且用户确认提交 发更新请求
              const userdata = {
                reUserInfo: this.userInfo
              };
              const loading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)"
              });
              this.axios
                .post("/referee/manage/re", JSON.stringify(userdata))
                .then(result => {
                  loading.close();
                  if (result.data.code === "0000") {
                    this.getOrgInfo();
                    this.$message({
                      message: "信息修改成功",
                      type: "info"
                    });
                  }
                })
                .catch(err => {});
            })
            .catch(() => {});
        } else {
          return false;
        }
      });
    },
    showJudg(type) {
      if (type === "new") {
        this.editSatus.judge = false;
        this.reJudgeFormVisable = true;
        this.reJudgeForm = {
          competitionLevel: "",
          competitionName: "",
          duty: "",
          endDate: "",
          evaluate: "",
          sponsor: "",
          startDate: "",
          undertaker: ""
        };
      } else {
        this.reJudgeFormVisable = true;
      }
      this.$nextTick(() => {
        this.$refs.reJudgeForm.clearValidate();
      });
    },
    addJudge() {
      this.$refs.reJudgeForm.validate(valid => {
        if (valid) {
          this.reJudgeForm.reId = this.userId;
          if (this.editSatus.judge) {
            // 编辑模式
            this.axios
              .put("/referee/manage/re/judge", JSON.stringify(this.reJudgeForm))
              .then(result => {
                this.reJudgeFormVisable = false;
                this.getJudgeList();
                // 重新获取执裁列表
              })
              .catch(err => {});
          } else {
            this.axios
              .post(
                "/referee/manage/re/judge",
                JSON.stringify(this.reJudgeForm)
              )
              .then(result => {
                this.reJudgeFormVisable = false;
                this.getJudgeList();
                // 重新获取执裁列表
              })
              .catch(err => {});
          }
        }
      });
    },
    // 删除执裁经历
    reJudgeListDel(index, row) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const judgeId = row.id;
          this.axios
            .delete(`/referee/manage/re/judge/${judgeId}`)
            .then(result => {
              if (result.data.code === "0000") {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
              }
              this.getJudgeList();
            })
            .catch(err => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },

    showreJudgeListEdit(index, row) {
      this.editSatus.judge = true;

      this.showJudg("edit");
      this.reJudgeForm = {
        id: row.id,
        competitionLevel: Number(row.competitionLevel),
        competitionName: row.competitionName,
        duty: Number(row.duty),
        endDate: row.endDate,
        evaluate: row.evaluate,
        sponsor: row.sponsor,
        startDate: row.startDate,
        undertaker: row.undertaker
      };
    },
    // 获取资格列表
    getQualification() {
      this.axios
        .get(`/referee/manage/re/qualification/list?reId=${this.userId}`)
        .then(result => {
          this.qualificationList = result.data.data;
        })
        .catch(err => {
          this.$message({
            message: result.data.msg,
            type: "warning"
          });
        });
    },
    // 编辑资格列表
    handleEditqualification(index, row) {
      this.editSatus.qualification = true;
      this.showQualification("edit");

      this.qualificationForm.id = row.id;
      this.qualificationForm.approveDate = row.approveDate;
      this.qualificationForm.certificateNum = row.certificateNum;
      this.qualificationForm.approveOrg = row.approveOrg;
      this.qualificationForm.grade = row.grade;
      this.qualificationForm.level = row.level;
    },
    // 删除资格列表
    handleDelqualification(index, row) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const qualificationId = row.id;
          this.axios
            .delete(`/referee/manage/re/qualification/${qualificationId}`)
            .then(result => {
              if (result.data.code === "0000") {
                this.$message({
                  type: "success",
                  message: "删除成功!"
                });
              }
              this.getQualification();
            })
            .catch(err => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 获取培训列表
    getTrainList() {
      this.axios
        .get(`/referee/manage/re/train/list?reId=${this.userId}`)
        .then(result => {
          this.reTrainList = result.data.data;
        })
        .catch(err => {
          this.$message({
            message: result.data.msg,
            type: "warning"
          });
        });
    },
    // 获取执裁列表
    getJudgeList() {
      this.axios
        .get(`/referee/manage/re/judge/list?reId=${this.userId}`)
        .then(result => {
          this.reJudgeList = result.data.data;
        })
        .catch(err => {
          this.$message({
            message: result.data.msg,
            type: "warning"
          });
        });
    },
    getUserInfo(){
      this.axios
        .get(`/referee/manage/re/${this.userId}`)
        .then(result => {
          if (result.data.code === "0000" && result.data.data.id) {
            this.userInfo = result.data.data;
            this.userInfo.gender = result.data.data.gender.toString();
            this.userInfo.birthday = result.data.data.birthday.slice(0, 10);
            this.getOrgInfo();
          } else {
            this.$message({
              message: result.data.msg,
              type: "warning"
            });
          }
        })
        .catch(err => {});
    },
  },
  
  mounted() {
    this.userId = this.$route.query.userId;
    this.nations = mycommon.nations;
    // 获取对应id裁判员的基本信息 初始化 第一个tab
    this.getUserInfo();
    // 获取裁判员等级，并初始化数据
    getReLeve()
      .then(res => {
        if (res.data.code === "0000") {
          this.relevel = res.data.data.list.filter(level => {
            return level.isDel === 0;
          });
          this.relevel.forEach(level => {
            if (level.isDel === 0) {
              this.releveldict["lv" + level.id] = level.dictName;
            }
          });
        }
      })
      .catch(err => {});

    // 初始化赛事级别
    getComLeve()
      .then(res => {
        if (res.data.code === "0000") {
          this.recomlevel = res.data.data.list.filter(level => {
            return level.isDel === 0;
          });
          this.recomlevel.forEach(level => {
            if (level.isDel === 0) {
              this.recomleveldict["lv" + level.id] = level.dictName;
            }
          });
        }
      })
      .catch(err => {});
    // 初始化职务级别
    getPositionLeve()
      .then(res => {
        if (res.data.code === "0000") {
          this.repositionlevel = res.data.data.list.filter(level => {
            return level.isDel === 0;
          });
          this.repositionlevel.forEach(level => {
            if (level.isDel === 0) {
              this.repositionleveldict["lv" + level.id] = level.dictName;
            }
          });
        }
      })
      .catch(err => {});
  }
};
</script>
<style scoped>

</style>


